package com.vichat.gps.controller;


import com.vichat.gps.service.IGpsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


/**
 * Created by wangluyin on 2017/8/23.
 */
@Component
public class GpsThreadInit implements ApplicationContextAware {

    private static transient Logger logger = LoggerFactory.getLogger(GpsThreadInit.class);


    public static GpsAppCache gpsAppCache = new GpsAppCache();


    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
        try {

            IGpsService gpsService = (IGpsService) ctx.getBean("gpsService", IGpsService.class);

            Thread thread = new Thread(new SaveGpsThread(gpsService, gpsAppCache));
            thread.start();

        } catch (Exception e) {
            logger.error("ApplicationCache初始化失败", e);
        }
    }
}
